﻿using System;

namespace Alex.Library.Log
{
    /// <summary>
    /// 自定义日志
    /// </summary>
    public class CustomLogger : LoggerBase
    {
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public CustomLogger() { }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="adapter">日志输出适配器</param>
        public CustomLogger(IFlushAdapter adapter)
        {
            this.FlushAdapter = adapter;
        }

        /// <summary>
        /// 日志输出适配器
        /// </summary>
        public IFlushAdapter FlushAdapter { get; set; }

        /// <summary>
        /// 将日志通过适配器输出到自定义的客户端
        /// </summary>
        /// <param name="level">日志级别</param>
        /// <param name="message">消息</param>
        protected override void DoFlush(LogLevel level, string message)
        {
            try
            {
                string content = this.Template.Format(level, message);
                this.FlushAdapter.Flush(level, DateTime.Now, content);
            }
            catch (Exception ex)
            {

            }
        }
    }
}
